﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.UI.Controls;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Telerik.Windows.Controls.GridView;
using Baosight.ZNH.ZMCM.UI.Utils;
using Baosight.Platform.Core.ServiceModel;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCM.UI.ChildWindows;
using Telerik.Windows.Controls;

namespace Baosight.ZNH.ZMCM.UI
{
    public partial class ZMCMI0 : EFViewCmes
    {
        public ZMCMI0()
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
        }

        /// <summary>
        /// 修改前设置属性
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.EFGridCheckedRows = this.grid.GetCheckedEIRows();
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnInsertButtonClick(object sender, RoutedEventArgs e)
        {
            base.OnInsertButtonClickPopup(new EIInfo(), "计划类型对应管理--新增", "insert", "", sender, e);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnUpdateButtonClick(object sender, RoutedEventArgs e)
        {
            IList<EIRow> _list = this.grid.GetCheckedEIRows() == null ? new List<EIRow>() : this.grid.GetCheckedEIRows();
            EIInfo eiInfo = new EIInfo();
            EIBlock eIBlock = new EIBlock("result");
            EIRow row = new EIRow();
            if (_list.Count > 0)
            {
                row = BaseTools.GetEIRowByOldEIRow(this.EIDataContext.GetBlock("result").GetColumns(), _list[0]);
            }
            eIBlock.SetRow(0, row);
            eiInfo.AddBlock(eIBlock);

            base.OnUpdateButtonClickPopup(eiInfo, "计划类型对应管理--修改", "update", null, sender, e);
        }

        public override void OnDeleteButtonClick(object sender, RoutedEventArgs e)
        {
            base.OnDeleteButtonClick("ZMCMI0", "delete", sender, e);
        }
        
        /// <summary>
        /// 弹出窗口方法
        /// </summary>
        /// <param name="_eIInfo"></param>
        /// <param name="_title"></param>
        /// <param name="_dialogType"></param>
        /// <param name="_args"></param>
        public override void OpenPopup(EIInfo _eIInfo, string _title, string _dialogType, string _args)
        {
            PlanTypeRelation planTypeWindow = new PlanTypeRelation(_dialogType);
            planTypeWindow.EIDataContext = new Platform.Core.UI.EIDataContext();
            _eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cm.planType"));
            _eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cm.defaultPlanType"));
            planTypeWindow.EIDataContext.Update(_eIInfo);

            CmesWindows _popup = new CmesWindows();//构造一个弹出页面
            _popup.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
            _popup.Header = _title == null ? "" : _title;//设置Title
            _popup.Content = planTypeWindow;//让新增页面在弹出窗口显示
            _popup.Closed += new EventHandler<WindowClosedEventArgs>(OperationWindow_Closed);
            _popup.ShowDialog();//模态显示弹出窗口
        }
        
        /// <summary>
        /// 发料/回收料弹出窗口关闭时执行的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OperationWindow_Closed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == true)
            {
                //刷新Grid区域
                this.grid.Refresh();
            }
            //按钮生效
            base.TempButtonOpen(true);
        }
    }
}
